<?php
include('connection/connection.php');
include('config.php');
include_once('header.php');
include_once('menu.php');
$loc_id = $_SESSION['loc_id'];
$imageId=$_SESSION['id'];
$district_name = $_SESSION['district_name'];
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<script language="Javascript" type="text/javascript" src="js/ajaxFunction1_q1.js"></script>
<script type="text/javascript">
var wordLen = 250; // Maximum word length
function checkWordLen(obj)
{
	var len = obj.value.split(/[\s]+/);
	if(len.length > wordLen)
	{
		alert("You cannot put more than "+wordLen+" words in this text area.");
		obj.oldValue = obj.value!=obj.oldValue?obj.value:obj.oldValue;
		obj.value = obj.oldValue?obj.oldValue:"";
	return false;
	}
	return true;
}
</script>
<title>UFW Form</title>
</head>
<body>
<?php 
if(isset($_POST['submit']))
{ 
		$fclick = true;
		$folder1='index_map/'.$district_name;
		//$folder1=$district_name;
		if(!is_dir($folder1))
		{
			mkdir($folder1, 0777);
		}
		$folder2='photo/'.$district_name;
		//$folder2=$district_name;
		if(!is_dir($folder2))
		{
			mkdir($folder2, 0777);
		}
		$flname1=$_FILES['ind_map']['name'];
		//echo $flname123=$_FILES['ind_map']['type'];
		$flname1=$loc_id . "-" . $flname1;
		if($flname1!='')
		{
			$dir=$folder1.'/';
			//echo '<br>';
			//echo $dir;
			$upfile=$dir.$flname1;
			move_uploaded_file($_FILES['ind_map']['tmp_name'], $upfile); 
			//echo "<script>alert('Index map file is successfully uploaded')\n";
			//echo "";	
			$success1='Index map file is successfully uploaded';
	 	}
		$no_photo=$_POST['num_photo'];
		if($no_photo > 0)
		{
		for($i=1; $i<=$no_photo; $i++)
		{
			$flname=$_FILES['photo_file'.$i]['name'];
			//echo $flname123=$_FILES['ind_map']['type'];
			$flname=$loc_id . "-" . $flname;
			$finalname=$finalname.",".$flname;	
			if($flname!='')
			{
				//$dir="photo/";
				$dir=$folder2.'/';
				$upfile=$dir.$flname;
				move_uploaded_file($_FILES['photo_file'.$i]['tmp_name'], $upfile); 
				//echo "<script>alert('Photo/Image is successfully uploaded')\n";
				//echo "";
				$success2='Photos/Images are successfully uploaded';
			}
		}
         function blanck($var)
         {
         	if($var!="")
            {
               return $var;
            }
         }
		 $finalname=explode(",",$finalname);
	     $finalname=array_filter($finalname, "blanck");
	     $finalname=implode($finalname,",");
		}
		
		$elec_cost=$_POST['elec_cost'];
		$man_cost=$_POST['man_cost'];
		$chemical_cost=$_POST['chemical_cost'];
		$maintenance_cost=$_POST['maintenance_cost'];
		$remark=$_POST['remark'];
		$q1="UPDATE tbl_dtls_ufw_main SET elec_cost='$elec_cost', man_cost='$man_cost', chemical_cost='$chemical_cost', maintenance_cost='$maintenance_cost', remark='$remark', index_map='$flname1', photos='$finalname', status='1' WHERE id='$loc_id'";	
			//echo $q1;
			$r1=mysql_query($q1);
			if($r1)
			{
				//echo "success 1";	
				$relocatePage=true;	
			}
			else 
			{
				$errorIns="Error updating ufw_main table <br>";
			}
			$q="SELECT usertype FROM tbl_dtls_createuser WHERE loginid='$loginid'";
			//echo $q;
			$res=mysql_query($q);
			$x=mysql_fetch_array($res);
			$user_type=$x['usertype'];
			$user_id=$_SESSION['loginid'];
			$form_id=$_SESSION['form_id'];
			$user_name=$_SESSION['name'];
			//$user_type=$_SESSION['usertype'];
			$ip=$_SERVER['REMOTE_ADDR'];
			$qr1="INSERT INTO tbl_dtls_user_history(user_id, form_id, action_id, ip_address, modify_date, user_type, user_name) VALUES ('$user_id', '$form_id', '8', '$ip', NOW(), '$user_type', '$user_name')";
			//echo $q5;
			$result=mysql_query($qr1);
			if($result)
			{
				$relocatePage=true;
			}
			else 
			{
				$errorIns.="Error inserting user_history Table<br>";
			}		
			if($errorIns==0) 
			{
				echo'<span class="successmssg"><b>'.$success1.'<br>'.$success2.'</b></span>';
				echo'</br>';
				//echo'<span class="successmssg"><b>'.$success2.'</b></span>';
				//echo'</br>';
				echo'<span class="successmssg"><b>Congratulation!!</b><br/>You have successfully filled this Form.</span>';
				echo'</br>'; echo'</br>'; echo'</br>'; echo'</br>'; echo'</br>'; echo'</br>'; echo'</br>'; echo'</br>'; echo'</br>';echo'</br>'; echo'</br>'; 
				echo '<span class="successmssg">For filling another form click here <a href="ufw_1.php">UFW</a></span>';
				exit();
			}
			else 
			{ 
				echo $errorIns;exit;
			}
}
else
{
	$fclick = false;
	$flag=0;
}
?>
<div align="center">
<form name="ufw_5" id="ufw_5" action="" method="post" onSubmit="return ufw5();" enctype="multipart/form-data">
	<table border="0" width="750" id="table1" cellspacing="0" cellpadding="0">
		<tr>
			<td height="16">
			<p align="center">
			<font face="Verdana" style="font-size: 10pt; font-weight: 700" color="#000000">UFW</font></td>
		</tr>
		<tr>
			<td height="14">
				<p align="center">
				<font style="font-size: 8.5pt" face="Arial" color="#000000">Page 5</font></p>			</td>
		</tr>
		
		<tr>
			<td bgcolor="#C5D8EB" height="22"><font color="#000000">&nbsp;
			</font><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">
			Cost Detail</font></span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="750" id="table2" bgcolor="#FDF9EE" cellspacing="1" cellpadding="0">
				<tr>
					<td colspan="4">
					<span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="276" height="25">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Electricity Cost(Rs./Annum)&nbsp;(<img src="images/26rup1.jpg" width="10">)</font></td>
					<td colspan="3"><input type="text" name="elec_cost" id="elec_cost" size="21" class="txt" value="" onBlur="float2dec(this)"></td>
				</tr>
				<tr>
					<td width="276" height="23">
					 <font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Man Power Cost(Rs./Annum)&nbsp;(<img src="images/26rup1.jpg" width="10">)</font></td>
					<td colspan="3"><input type="text" name="man_cost" id="man_cost" size="21" class="txt" value="" onBlur="float2dec(this)"></td>
				</tr>
				<tr>
					<td width="276" height="24">
					 <font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Chemicals Cost(Rs./Annum)&nbsp;(<img src="images/26rup1.jpg" width="10">)</font></td>
					<td colspan="3"><input type="text" name="chemical_cost" id="chemical_cost" size="21" class="txt" value="" onBlur="float2dec(this)"></td>
				</tr>
				<tr>
					<td width="276" height="23">
					 <font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Maintenance Cost(Rs./Annum)&nbsp;(<img src="images/26rup1.jpg" width="10">)</font></td>
					<td colspan="3"><input type="text" name="maintenance_cost" id="maintenance_cost" size="21" class="txt" value="" onBlur="float2dec(this)"></td>
				</tr>
				<tr>
					
					<td colspan="4">&nbsp;</td>
				</tr>
				</table>			</td>
		</tr>
		<tr>
			<td><span style="font-size: 4pt">&nbsp;</span></td>
		</tr>
		<tr>
			<td bgcolor="#C5D8EB" height="22"><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">
			Remark / Recommendation</font></span></td>
		</tr>
		<tr>
			<td>
			<span style="font-size: 3pt">&nbsp;</span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="750" id="table6" bgcolor="#FDF9EE" cellspacing="1" cellpadding="0">
				<tr>
					<td width="37%" height="27">
					<font style="font-size: 8.5pt" face="Verdana" color="#000000">&nbsp;Remarks</font></td>
				  <td colspan="3"><textarea name="remark" id="remark" rows="5" cols="40" onChange="checkWordLen(this);"></textarea></td>
				</tr>
				<tr><td colspan="4">&nbsp;</td></tr>
				</table>			</td>
		</tr>
		<tr>
			<td><span style="font-size: 4pt">&nbsp;</span></td>
		</tr>
		<tr>
			<td bgcolor="#C5D8EB" height="22"><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">
			Upload Index Map and Photos</font></span></td>
		</tr>
		<tr>
			<td><span style="font-size: 4pt">&nbsp;</span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="750" id="table6" bgcolor="#FDF9EE" cellspacing="1" cellpadding="0">
			<tr>
					<td width="276" height="23">
					 <font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;Upload Index Map</font></td>
					<td colspan="3"><input type="file" name="ind_map" id="ind_map">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;*Upload Only .pdf File</font></td>
				</tr>
				<tr>
					<td width="276" height="23">
					 <font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;No. of Photos</font></td>
				  <td colspan="3"><input type="text" name="num_photo" id="num_photo" class="txt5" onKeyUp="numeric(this);show_photo_file()">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">&nbsp;*Upload Only .pdf File</font></td>
				</tr>
				<tr><td colspan="4"><span style="font-size: 4pt">&nbsp;</span></td></tr>
			   <tr><td colspan="4"><div id="photo_div"></div></td></tr>
				<tr><td colspan="4"><span style="font-size: 4pt">&nbsp;</span></td></tr>
			</table>			</td>
		</tr>
		
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>
			<p align="center">
			<input type="submit" value="Submit" name="submit" id="submit" style="font-family: Verdana;">&nbsp;			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		</table>
</form>
</div>
</body>
</html>